const db = require('./server/config/database')

async function testSimpleQuery () {
  try {
    console.log('测试简单查询...')

    // 不带参数的查询
    const novels1 = await db.query('SELECT * FROM novels LIMIT 3')
    console.log(`查询1成功: ${novels1.length} 条记录`)

    // 带一个参数的查询
    const novels2 = await db.query('SELECT * FROM novels WHERE id = ?', [1])
    console.log(`查询2成功: ${novels2.length} 条记录`)

    // 带两个参数的查询
    const novels3 = await db.query(
      'SELECT * FROM novels LIMIT ? OFFSET ?',
      [3, 0]
    )
    console.log(`查询3成功: ${novels3.length} 条记录`)

    // 测试路由中的查询
    const novels4 = await db.query(
      'SELECT * FROM novels WHERE 1=1 ORDER BY updated_at DESC LIMIT ? OFFSET ?',
      [5, 0]
    )
    console.log(`查询4成功: ${novels4.length} 条记录`)

    console.log('✅ 所有查询测试成功！')
  } catch (error) {
    console.error('❌ 查询测试失败:', error)
  } finally {
    process.exit(0)
  }
}

testSimpleQuery()
